package metadata

import (
	"os"

	"github.com/romberli/das/config"
	"github.com/romberli/das/global"
	"github.com/romberli/go-util/common"
	"github.com/romberli/go-util/constant"
	"github.com/romberli/go-util/middleware/mysql"
	"github.com/romberli/log"
	"github.com/spf13/viper"
)

const (
	testDASMySQLAddr = "192.168.137.11:3306"
	testDASMySQLName = "das"
	testDASMySQLUser = "root"
	testDASMySQLPass = "root"

	testDefaultServerPort = 6090
)

func testInitViper() {
	viper.Set(config.ServerPortKey, testDefaultServerPort)
	viper.Set(config.ServerDeploymentAccessibleZonesKey, []string{"test-region-01.test-org-01.test-network-zone-01"})
	viper.Set(config.RoleKey, config.ServerRole)
	viper.Set(config.PrivilegeSpecialTokensKey, []string{"f3171bd9-beec-11ec-acc0-000c291d6734"})
	viper.Set(config.DBApplicationMySQLUserKey, config.DefaultDBApplicationMySQLUser)
	viper.Set(config.DBApplicationMySQLPassKey, config.DefaultDBApplicationMySQLPass)
}

func testInitDASMySQLPool() {
	var err error

	if global.DASMySQLPool == nil {
		global.DASMySQLPool, err = mysql.NewPoolWithDefault(testDASMySQLAddr, testDASMySQLName, testDASMySQLUser, testDASMySQLPass)
		if err != nil {
			log.Error(common.CombineMessageWithError("testInitDASMySQLPool() failed", err))
			os.Exit(constant.DefaultAbnormalExitCode)
		}
	}
}
